//
//  Context.h
//  LightBasic
//
//  Created by Albert on 19/03/2011.
//  Copyright 2011 LightBasic Development Team. All rights reserved.
//
#pragma once
#include "SourceFile.h"

namespace lbc {
    
    /**
     * Resource container type
     */
    typedef std::vector<FS::path> ResourceContainer;
    
    /**
     * Compilation context
     * Context holds information about the compilation context
     * such as include paths, global defines, libraries etc.
     */
    class Context : boost::noncopyable
    {
        public:
        
        /**
         * Type of the resource
         */
        enum ResourceType {
            TypeGlobalPath,
            TypeSource,
            TypeSourcePath,
            TypeLibrary,
            TypeLibraryPath,
            TypeCount
        };
        
        /// Destructor
        virtual ~Context();
        
        /**
         * Add resource to the context
         */
        void Add(const std::string & path, ResourceType type);
        
        /**
         * Get the source from a file
         * will hold a weak reference to it
         */
        Source & GetSource(const FS::path & path);
        
        /**
         * Get resources of the given type
         * read-only
         */
        const ResourceContainer & GetResources(ResourceType type) const;
        
        private:
        
        /// SourceFiles
        std::vector<SourceFile*> m_opensources;
        
        /// Resolve directory path
        FS::path ResolveDir(const std::string & dir) const;
        
        /// resolve resource path against the container
        FS::path ResolveFile(const std::string & file, const ResourceContainer & container) const;
        
        /// array that contains the resources
        ResourceContainer m_resources[TypeCount];
    };
    
}
